<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>快速开店</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="css/newshop.css"/>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/jquery-3.3.1.min.js"></script>
    <script src="js/jquery.cookie.js"></script>
</head>
<body>
    <div class="container" id="returnindex">
        <div class="row">
            <div class="col-xs-11 col-sm-11 col-md-11 col-lg-11"></div>
            <div class="col-xs-1 col-sm-1 col-md-1 col-lg-1"><a href="index.html">返回首页</a></div>
        </div>
    </div>
    <div class="container" id="pagetitle">
        <div class="row">
            <div class="col-xs-1 col-sm-1 col-md-1 col-lg-1"></div>
            <div class="col-xs-11 col-sm-11 col-md-11 col-lg-11"><p><span>果蔬网</span>&nbsp;开店流程</p></div>
        </div>
    </div>
    <div class="container" id="newshopbody">
        <div id="wangshop">我要开店</div>
        <div id="tishi">果蔬网申请开店，需要完成以下四步：</div>
        <div class="row" id="step">
            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3"><div class="stepchoise" id="step1"><p>1<span>&nbsp;&nbsp;阅读开店须知</span></p></div></div>
            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3"><div class="step" id="step2"><p>2<span>&nbsp;&nbsp;完善个人信息</span></p></div></div>
            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3"><div class="step" id="step3"><p>3<span>&nbsp;&nbsp;填写店铺信息</span></p></div></div>
            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3"><div class="step" id="step4"><p>4<span>&nbsp;&nbsp;等待审核通过</span></p></div></div>
        </div>
        <div class="container" id="stepdetails">
            <div class="question">
                <p>1.申请开店需要满足那些条件？</p>
                <span>答：申请开店需要在本网站完善除头像和昵称以外的个人信息（如未完善请前往首页在左上角前往完善）;除此之外注册本网站的手机号码，还必须注册开通了支付宝;作为店铺负责人，需要对该店铺的运营及管理全面负责，且有承担责任与风险的能力。</span>
            </div>
            <div class="question">
                <p>2.我可以开多少个店铺？</p>
                <span>答：1个，为了便于管理，一个用户最多可申请一个店铺，但是本网站不限定发货地址，店铺负责人可放心销售不同地区的产品，但必须保证发货的速度与产品的质量，由此产生的任何问题，本网站概不负责。</span>
            </div>
            <div class="question">
                <p>3.我可以在店铺内售卖其他产品么？</p>
                <span>答：不可以，本网站开店申请，以及商品的上架，都有专门的负责人负责审核，本网站只限定于售卖果蔬一类的产品，因店铺或商品违规造成店铺被封禁，本网站概不负责。</span>
            </div>
            <div class="question">
                <p>4.店铺为什么会被封禁？</p>
                <span>答：售卖非法商品，店铺名称违规，头像违规，商品名称违规，恶意竞争。</span>
            </div>
            <div><button id="iknow">我已了解，继续开店</button></div>
        </div>
    </div>

    <script type="text/javascript">

        var userId = $.cookie("userId");

        if (userId == null){
            location.href = "login.html";
        }

        function isNormalInput(ipt){
            return ipt.val() != null && ipt.val().length != 0 && !ipt.hasClass("error_input");
        }

        $("#iknow").click(function () {

            $("#step1").removeClass("stepchoise");
            $("#step1").addClass("step");
            $("#step2").removeClass("step");
            $("#step2").addClass("stepchoise");

            var ht = '<div class="row informationrow" id="titlerow">' +
                '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">条件检测</div>' +
                '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">状态</div>' +
                '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">提示</div>' +
                '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">操作</div>' +
                '</div>';
            // $("#stepdetails").html("");
            $("#stepdetails").html(ht);

            $.post("user/information",{userId:userId},function (data) {

                var information = JSON.parse(data);

                var nameState,nameTishi,nameAction,sexState,sexTishi,sexAction,birState,birTishi,birAction;

                if(information.name == null){
                    nameState = '未通过';
                    nameTishi = '尚未完善';
                    nameAction = '<a href="updata_information.html">前往完善</a>';
                }else {
                    nameState = '已通过';
                    nameTishi = '已完善';
                    nameAction = '无';
                }

                if(information.sex == null){
                    sexState = '未通过';
                    sexTishi = '尚未完善';
                    sexAction = '<a href="updata_information.html">前往完善</a>';
                }else {
                    sexState = '已通过';
                    sexTishi = '已完善';
                    sexAction = '无';
                }

                if(information.birthday == null){
                    birState = '未通过';
                    birTishi = '尚未完善';
                    birAction = '<a href="updata_information.html">前往完善</a>';
                }else {
                    birState = '已通过';
                    birTishi = '已完善';
                    birAction = '无';
                }



                var ht = '<div class="row informationrow" id="titlerow">' +
                             '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">条件检测</div>' +
                             '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">状态</div>' +
                             '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">提示</div>' +
                             '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">操作</div>' +
                         '</div>';
                ht += '<div class="row informationrow">' +
                         '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">姓名</div>' +
                         '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">'+ nameState +'</div>' +
                         '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">'+ nameTishi +'</div>' +
                         '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">'+ nameAction +'</div>' +
                      '</div>';
                ht += '<div class="row informationrow">' +
                    '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">性别</div>' +
                    '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">'+ sexState +'</div>' +
                    '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">'+ sexTishi +'</div>' +
                    '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">'+ sexAction +'</div>' +
                    '</div>';
                ht += '<div class="row informationrow">' +
                    '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">生日</div>' +
                    '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">'+ birState +'</div>' +
                    '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">'+ birTishi +'</div>' +
                    '<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 informationtable">'+ birAction +'</div>' +
                    '</div>';

                ht += '<button id="prev">返回重来</button><button id="next">下一步</button>';

                $("#stepdetails").html(ht);

                $("#prev").click(function () {
                   location.href = "newshop.html";
                });

                $("#next").click(function () {
                    if (nameState == '已通过' && sexState == '已通过' && birState == '已通过'){
                        $("#step2").removeClass("stepchoise");
                        $("#step2").addClass("step");
                        $("#step3").removeClass("step");
                        $("#step3").addClass("stepchoise");

                        ht = '<div id="redp"><p>温馨提示：店铺名称与头像，一经确定，无法修改，请谨慎选择</p></div>';
                        ht += '<div class="shopinformation" id="shopinformation">店铺名称：<input type="text" id="shopname"></div>';
                        ht += '<div class="shopinformation">店铺头像：<input type="file" id="shophs" title="" accept="image/png,image/jpeg"></div>';
                        ht += '<div class="reason">申请理由：<textarea id="reason"></textarea></div>';
                        ht += '<button id="prev1">重新申请</button><button id="next1">提交审核</button>';
                        $("#stepdetails").html(ht);


                        $("#shopname").focus(function () {

                            $("#shopname").removeClass("error_input");

                        });

                        $("#shophs").focus(function () {

                            $("#shophs").removeClass("error_input");

                        });

                        $("#reason").focus(function () {

                            $("#reason").removeClass("error_input");

                        });


                        $("#prev1").click(function () {
                            location.href = "newshop.html";
                        });

                        $("#next1").click(function () {

                            var shopname = $("#shopname").val();
                            var reason = $("#reason").val();

                            if (isNormalInput($("#shopname")) && isNormalInput($("#shophs")) && isNormalInput($("#reason"))) {
                                var formData = new FormData();
                                formData.append('file', $("#shophs")[0].files[0]); // 固定格式
                                formData.append('userId', userId);
                                formData.append('shopname', shopname);
                                formData.append('reason', reason);

                                $.ajax({
                                    url: "shop/newShop",
                                    data:formData,
                                    type: "POST",
                                    dataType: "json",
                                    cache: false,			//上传文件无需缓存
                                    processData: false,		//用于对data参数进行序列化处理 这里必须false
                                    contentType: false,
                                    mimeType: "multipart/form-data",
                                    success:function(data){
                                        if (data.code.toLowerCase() == "success"){
                                            alert("提交审核成功！请耐心等待审核通过！");
                                            location.href = "index.html";
                                        }else{
                                            alert("提交审核失败！请稍后再试");
                                        }
                                    }
                                });

                            }else {
                                if (!isNormalInput($("#shopname"))) {
                                    if (!$("#shopname").hasClass("error_input")) {
                                        $("#shopname").addClass("error_input");
                                    }
                                }
                                if (!isNormalInput($("#shophs"))) {
                                    if (!$("#shophs").hasClass("error_input")) {
                                        $("#shophs").addClass("error_input");
                                    }
                                }
                                if (!isNormalInput($("#reason"))) {
                                    if (!$("#reason").hasClass("error_input")) {
                                        $("#reason").addClass("error_input");
                                    }
                                }
                            }

                        });
                    }
                });
            });


        });

    </script>

</body>
</html>